<?php

namespace App\Jobs;

use App\Facades\SamLogFacade;
use Carbon\Carbon;
use Exception;
use App\Models\UserCertOcr;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;

class CheckCertValidJob implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    /**
     * Create a new job instance.
     *
     * @return void
     */
    public function __construct()
    {
        //
    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
        $date = date('Y-m-d');
        SamLogFacade::debug(Carbon::now()."检查{$date}的身份证");
        try{
            UserCertOcr::whereDate('valid_date_end', $date)
                ->update(['is_valid'=>0]);
        }catch (Exception $exception){
            SamLogFacade::debug('error',"身份证检查有效期错误：".$exception->getMessage());
        }
    }
}
